package com.zut.edu.widget;

import android.util.Log;

import com.zut.edu.bean.Chart;

import java.util.ArrayList;
import java.util.List;

import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.AxisValue;
import lecho.lib.hellocharts.model.Column;
import lecho.lib.hellocharts.model.ColumnChartData;
import lecho.lib.hellocharts.model.SubcolumnValue;
import lecho.lib.hellocharts.model.Viewport;
import lecho.lib.hellocharts.util.ChartUtils;
import lecho.lib.hellocharts.view.ColumnChartView;

/**
 * Created by kang on 2020/12/5.
 */

public class ColumnChartTool {

    private static final String TAG = "Tools";

    public static void setChartViewData(List<Chart>charList, ColumnChartView columnChart) {
        ColumnChartData mColumnChartData;
        List columnList = new ArrayList<>(); //柱子列表
        String[] xValues = new String[12];
        List subcolumnValueList; //子柱列表(即一个柱子，因为一个柱子可分为多个子柱)
        List axisValues = new ArrayList<>();//创建x轴数据
        float[] yValues = new float[12];

        for(int i=0;i<charList.size();i++){
            xValues[i]=charList.get(i).getTime();
            yValues[i]=charList.get(i).getData();
        }

        for (int i = 0; i < 12; ++i) {

            subcolumnValueList= new ArrayList<>();//每个子柱的集合
            subcolumnValueList.add(new SubcolumnValue(yValues[i],ChartUtils.pickColor()));//每个子柱集合的数据
            axisValues.add(new AxisValue(i).setLabel(xValues[i]));
            Column column= new Column(subcolumnValueList);//创建子柱数据
            column.setHasLabels(true); //设置列标签
            columnList.add(column);//添加柱子数据

        }

        mColumnChartData= new ColumnChartData(columnList); //设置数据

        /*===== 坐标轴相关设置 =====*/
        Axis axisX= new Axis(axisValues);//设置横坐标柱子下面的分类
        Axis axisY = new Axis().setHasLines(true);
        axisX.setName("时间"); //设置横轴名称
        axisY.setName("审核人数"); //设置竖轴名称
        mColumnChartData.setAxisXBottom(axisX); //设置横轴
        mColumnChartData.setAxisYLeft(axisY); //设置竖轴
        columnChart.setZoomEnabled(false);//不可点击//以上所有设置的数据、坐标配置都已存放到mColumnChartData中，接下来给mColumnChartView设置这些配置
        columnChart.setColumnChartData(mColumnChartData);
        Viewport v=columnChart.getMaximumViewport();//设置ｙ轴的长度
        v.top= 50;
        columnChart.setCurrentViewport(v);
    }
}
